﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Mirkuz.UI
{   
    public enum VerticalAlignment {Top,Center,Bottom};
    public class TLabel : TBaseControl
    {

        public TLabel() : base()
        {
            TextAlign = ContentAlignment.TopCenter;
            VerticalAlign = VerticalAlignment.Center;
        }             
      
        public ContentAlignment TextAlign
        {
            get;set;
        }
        
        public VerticalAlignment VerticalAlign
        {
            get;set;
        }

        protected override void OnPaint(PaintEventArgs pe)
        {                                    
            SizeF s=pe.Graphics.MeasureString(Text, Font);

            //horizontal align
            float l = 0;
            if (TextAlign == ContentAlignment.TopCenter && s.Width < Width)
                l = ((Width - s.Width) / 2);

            if (TextAlign == ContentAlignment.TopRight && s.Width < Width)
                l = (Width - s.Width);

            //vertical align
            float t = 0;
            if (VerticalAlign == VerticalAlignment.Center && s.Height < Height)
                t = ((Height - s.Height) / 2);

            if (VerticalAlign== VerticalAlignment.Bottom && s.Height < Height)
                t = (Height - s.Height);

            //draw text
            RectangleF rf = new RectangleF(l, t, Width, Height);
            pe.Graphics.DrawString(Text,
                Font,
                new SolidBrush(ForeColor),
                rf);
        }
    }

}
